package com.strato.base.aop.v1_0_0;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

import com.strato.base.aop.v1_0_0.inline.DelegateMethodInterceptor;
import com.strato.classloader.v1_0_0.OverallBundleContextClassLoader;

public class AopFactory {

	public static Object createProxy(Class<?> clazz,InvocationInterceptor interceptor){
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(clazz);
		enhancer.setClassLoader(OverallBundleContextClassLoader.getInstance());
		MethodInterceptor callback=new DelegateMethodInterceptor(interceptor);
		enhancer.setCallback(callback);
		Object instance= enhancer.create();
		return instance;
	}
	
	
	public static boolean isProxied(Class<?> clazz){
		return Enhancer.isEnhanced(clazz);
	}
	
}
